package cn.rkylin.oms.aftersale.event.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.PageInfo;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.aftersale.event.dao.IAfterSaleEventDAO;
import cn.rkylin.oms.aftersale.event.domain.AfterSaleEvent;
import cn.rkylin.oms.aftersale.event.vo.AfterSaleEventVO;

/**
 * 类名:AfterSaleEventDAOImpl <br/>
 * 作用: 售后事件数据访问类. <br/>
 * 创建原因: 售后事件数据访问. <br/>
 * 创建时间: 2017年9月25日 下午1:34:23 <br/>
 * 
 * @author zhanghao
 * @version v1.0
 */
@Repository
public class AfterSaleEventDAOImpl implements IAfterSaleEventDAO {
    @Autowired
    private IDataBaseFactory dao;

    private static final String STATEMENT_PAGE_SELECT_BY_CONDITION = "pageSelectAfterSaleEvent";
    private static final String STATEMENT_SELECT_BY_ORDERID = "selectByOrderId";
    private static final String STATEMENT_UPDATE_BY_CONDITION = "updateAfterSaleEvent";
    private static final String STATEMENT_INSERT = "insertAfterSaleEvent";

    /**
     * 构造器：AfterSaleEventDAOImpl.
     *
     */
    public AfterSaleEventDAOImpl() {

    }

    /**
     * selectPagedByCondition:分页查询售后事件.
     */
    @Override
    public PageInfo<AfterSaleEventVO> selectPagedByCondition(int page, int rows, AfterSaleEventVO eventVO) throws Exception {
        return dao.findPage(page, rows, STATEMENT_PAGE_SELECT_BY_CONDITION, eventVO);
    }

    /**
     * selectByPrimaryKey:根据事件ID查询售后事件.
     */
    @Override
    public AfterSaleEvent selectByPrimaryKey(String eventId) throws Exception {

        AfterSaleEventVO result = null;

        AfterSaleEventVO eventVO = new AfterSaleEventVO();
        eventVO.setEventId(eventId);
        List<AfterSaleEventVO> returnList = selectByCondition(eventVO);

        if (returnList.size() > 0) {
            result = returnList.get(0);
        }
        return result;
    }

    /**
     * insert:新增售后事件
     */
    @Override
    public int insert(AfterSaleEvent record) throws Exception {
        return dao.insert(STATEMENT_INSERT, record);
    }

    /**
     * update:更新售后事件.
     */
    @Override
    public int update(AfterSaleEvent record) throws Exception {
        return dao.update(STATEMENT_UPDATE_BY_CONDITION, record);
    }

    /**
     * selectByCondition：根据查询条件获取售后事件数据
     */
    @Override
    public List<AfterSaleEventVO> selectByCondition(AfterSaleEventVO eventVO) throws Exception {
        return dao.findAllList(STATEMENT_PAGE_SELECT_BY_CONDITION, eventVO);
    }

    /**
     * 获取系统订单对应售后事件列表 wangxing 2017-12-04 add
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public List<AfterSaleEventVO> selectByOrderId(String orderId) throws Exception {
        return dao.findList(STATEMENT_SELECT_BY_ORDERID, orderId);
    }

}
